package com.paad.todolist;

import android.content.Context;
import java.util.*;
import android.view.*;
import android.widget.*;

public class SquadBattlegridAdapter extends ArrayAdapter<Squad> {

  int resource_id;
  Context con;

  public SquadBattlegridAdapter(Context _context, 
                             int _resource_id, 
                             List<Squad> _items) {
    super(_context, _resource_id, _items);
    resource_id = _resource_id;
    con = _context;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
	  View v = convertView;
      if (v == null) {
          LayoutInflater vi = (LayoutInflater)con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          v = vi.inflate(R.layout.squad_battlegrid, null);
      }

    Squad sq = getItem(position);
    
    if(sq != null)
    {
    	TextView tv = (TextView) v.findViewById(R.id.battlegridSquadText);
    	if(tv != null)
    	{
    		tv.setText(sq.name + " x" + sq.currentUnits);
    	}
    	ImageView iv = (ImageView) v.findViewById(R.id.battlegridSquadImage);
    	if( iv != null)
    	{
    		//TODO: switch of images based on squad type.
    		iv.setImageResource(R.drawable.icon);
    	}
    }
    

    return v;
  }
}
